<?php

/**
* @author PEpeSto
* @license MPL 1.1
*/
$fileName = "config.ini";

$iniArray =array();
$lines = file($fileName) or die("Error: Can't read file");
$currentBlock="";
foreach ($lines as $linenum=&gt;$line)
{
    // comments
    if(preg_match("/^[ \t]*;/",$line)) continue;
    // blocks
    if(preg_match("/^[ \t]*\[(.+?)\][ \t]*/", $line, $matches)) $currentBlock = $matches[1];
    
    // params
    if(preg_match("/^[ \t]*(.+?)[ \t]*=[ \t]*(.+)/", $line, $matches))
    if(preg_match("/^(.+?)\[(.*)\]/", $matches[1], $matches2))
        ($currentBlock!="")
            ? (($matches2[2]!="")
                ? $iniArray[$currentBlock][$matches2[1]][$matches2[2]] = $matches[2]
                : $iniArray[$currentBlock][$matches2[1]][] = $matches[2])
            : (($matches2[2]!="")
                ? $iniArray[$matches2[1]][$matches2[2]] = $matches[2]
                : $iniArray[$matches2[1]][] = $matches[2]);
    else
        ($currentBlock!="")
            ? $iniArray[$currentBlock][$matches[1]] = $matches[2]
            : $iniArray[$matches[1]] = $matches[2];
}

print_r($iniArray);
?>
